package com.kaishengit.service;

import java.util.List;

import com.kaishengit.dao.ContactNoteDao;
import com.kaishengit.entity.ContactNote;
import com.kaishengit.util.DateUtil;
import com.kaishengit.util.IntervalUtil;
import com.kaishengit.util.PKUtil;

public class ContactNoteService {
	ContactNoteDao dao = new ContactNoteDao();

	public List<ContactNote> findById(String id) {
		List<ContactNote> list = dao.findById(id);
		for(ContactNote cn : list) {
			String interval = IntervalUtil.getInterval(cn.getCreatetime());
			cn.setCreatetime(interval);
		}
		
		return list;
	}

	public void addNote(String contactid, String content, String employeeId) {
		ContactNote cn = new ContactNote();
		cn.setContactid(contactid);
		cn.setContent(content);
		cn.setCreatetime(DateUtil.getNow());
		cn.setEmployeeid(employeeId);
		cn.setId(PKUtil.getPK());
		
		dao.saveNote(cn);
		
	}

	public List<ContactNote> findAllById(String contactid) {
		List<ContactNote> list = dao.findAllById(contactid);
		for(ContactNote cn : list) {
			String interval = IntervalUtil.getInterval(cn.getCreatetime());
			cn.setCreatetime(interval);
		}
		
		return list;
	}
}
